package br.com.jmmarca.controller;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import br.com.jmmarca.dao.impl.EventoDAO;
import br.com.jmmarca.model.Evento;

public class ListarEventoActivity extends ListActivity {
	private List<Evento> eventos;
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);

		EventoDAO eventoDAO = EventoDAO.getInstance(getApplicationContext());
		eventos = eventoDAO.listar();
		
		ArrayAdapter<Evento> adapter = new ArrayAdapter<Evento>(this,
				android.R.layout.simple_list_item_1, eventos);
		setListAdapter(adapter);
	}
	  @Override
	  public void onListItemClick(ListView l, View v, int position, long id) {
	    // Do something with the data
		   Evento evento = eventos.get((int)id);
		   Intent intent = getIntent();
		   intent.putExtra("idEvento", evento.getId());
		   setResult(1, intent);
		   finish();
	  }
}